#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "f2c.h"

void s_set_PB1_30( real* d, real* e);

void sbdsqr_( char *uplo, integer *n, integer *ncvt, integer *nru, integer *ncc,
   real *d, real *e, real *vt, integer *ldvt, real *u,
   integer *ldu, real *c, integer *ldc, real *work, integer *info );

int main() {

   real *d=NULL, *e=NULL;
   integer n = 30;
   integer ncvt=0, ncc=0, nru=0;
   real *vt=NULL;
   real *u=NULL;
   real *c=NULL;
   real *work;
   integer ldu=1, ldvt=1, ldc = 1;
   integer info;
   integer i;

   work = (real *)malloc(4*n*sizeof(real)) ;

   d = (real *)malloc(n*sizeof(real)) ;
   e = (real *)malloc(n*sizeof(real)) ;
   s_set_PB1_30( d, e);

   sbdsqr_( "U", &n, &ncvt, &nru, &ncc, d, e, vt, &ldvt, u, &ldu, c, &ldc, work, &info );
   for (i=0;i<n;i++){
      printf("s(%2ld) = %e\n",i+1,d[i]);
   }
   if (info == 0 ){
      printf("info = %ld            ",info);
      printf("sigma_max( B ) = %f  ",d[0]);
      printf("sigma_min( B ) = %f\n",d[n-1]);
   } else {
      printf("info = %ld\n",info);
   }

   free(work);
   free(d);
   free(e);
   return 0;
}
